<?php 

Class indexModel extends appModel
{

	public function getFavor()
	{
		$sql="SELECT * FROM ".$this->table('favor')." where admin_id=".$_SESSION['admin_id'];
		return $this->getAll($sql);
	}
	
	/**
	 * 确认用户信息
	 * @param $username
	 * @param $password
	 * @return boolean
	 */
	public function check_user($username,$password)
	{
		$sql = "SELECT u.id, u.password, u.username, ar.role_action, ar.role_mod FROM " . $this->table('admin').
                   " as u," . $this->table('admin_role').
                   " as ar WHERE u.group_id=ar.id AND u.username = '" . $username .  "' AND u.password = '" . md5($password). "'";
		$row = $this->getRow($sql);
            
        if ($row&&$username==$row['username']&&md5($password)==$row['password'])
        {
         	session('admin_id',$row['id']);
        	session('admin_name',$row['username']);
            session('admin_action',$row['role_action']);
            session('admin_mod',$row['role_mod']);
            cookie('QIAQIA[admin_id]',   $row['id'],array('expire'=>3600*24));
            cookie('QIAQIA[admin_pass]', md5($row['password']),array('expire'=>3600*24));
            return true;
        }
        else
        {
        	return false;
        }
    }
}